﻿using _02.StudentsService.Controllers;
using _02.StudentsService.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Students.Services.Controllers
{
    public class StudentsController : ApiController
    {
        private List<Student> students;

        public StudentsController()
        {
            this.students = new List<Student>()
                            {
                                new Student()
                                {
                                    Id = 1,
                                    Age = 44,
                                    FirstName = "Dobi",
                                    LastName = "Haho",
                                    Marks =
                                        new List<Mark>()
                                        {
                                            new Mark()
                                            {
                                                Score = 2,
                                                Subject =
                                                    "Math"
                                            },
                                            new Mark()
                                            {
                                                Score = 3,
                                                Subject =
                                                    "Bio"
                                            },
                                            new Mark()
                                            {
                                                Score = 6,
                                                Subject =
                                                    "Geo"
                                            }
                                        }
                                }, new Student()
                                {
                                    Id = 2,
                                    Age = 22,
                                    FirstName = "Saho",
                                    LastName = "Bashe",
                                    Marks =
                                        new List<Mark>()
                                        {
                                            new Mark()
                                            {
                                                Score = 4,
                                                Subject =
                                                    "Math"
                                            },
                                            new Mark()
                                            {
                                                Score = 5,
                                                Subject =
                                                    "Bio"
                                            }
                                        }
                                }
                            };
        }

        public IEnumerable<Student> GetAllStudents()
        {
            return this.students;
        }

        [ActionName("marks")]
        public IEnumerable<Mark> GetAllMarksForStudent(int studentId)
        {
            return this.students.FirstOrDefault(x => x.Id == studentId).Marks;
        }
    }
}